"""

下载模块
pip install redis
注意点 也是需要把redis服务开启
"""
import redis
# 建立连接池对象
pool=redis.ConnectionPool(host="localhost",port=6379,decode_responses=False,db=0)
# 生成执行redis代码的对象
res1=redis.Redis(connection_pool=pool)

# 字符串
"""
注意点在 redis里面进行数据的写入 数据是以gbk进行编码 
如果在python里面往数据库进行值写入  查询时不需要进行gbk解码  
"""
# data=res1.get("a2")
# print(data.decode("gbk"))
# # 关闭连接
# res1.close()


# 哈希
# res1.hset("hashdata","a",1)
# data=res1.hget("hashdata","a")
# print(data.decode())

# 列表
# lie1=res1.lrange("lie1",0,-1)
# for i in lie1:
#     print(i.decode("gbk"))


# 集合
# res1.sadd("初识NLTK.py","值7","值6","值5","值4","值3","值2")
#
# ss=res1.smembers("初识NLTK.py")
# print(ss)
#
# for i in ss:
#     print(i.decode("utf-8"))
# lit1=list(ss)
# print(lit1)

res1.zadd("pai",{"G":1,"Lydia":2,"Day1":3})

pai=res1.zrange("pai",0,-1)
for i in pai:
    print(i.decode("utf-8"))
# 有序集合
# 关闭连接
res1.close()




















